package com.dubito.chat.util;

import com.dubito.chat.attribute.Attributes;
import io.netty.channel.Channel;
import io.netty.util.Attribute;

/**
 * @author liliang
 * @date 2020/4/27.
 */
public class LoginUtil {

    /**
     * 标记 Channel 已登录
     *
     * @param channel Channel 连接
     */
    public static void markAsLogin(Channel channel) {
        channel.attr(Attributes.LOGIN).set(true);
    }

    /**
     * 当前 Channel 是否登录
     *
     * @param channel Channel 连接
     * @return true/false
     */
    public static boolean hasLogin(Channel channel) {
        Attribute<Boolean> loginAttr = channel.attr(Attributes.LOGIN);

        return loginAttr.get() != null;
    }
}
